<?php if (!defined('THINK_PATH')) exit();?>


 <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Admin</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" type="text/css" href="/TPproject/project/Public/Admin/Css/bootstrap.css">
    
    <link rel="stylesheet" type="text/css" href="/TPproject/project/Public/Admin/Css/theme.css">
    <link rel="stylesheet" href="/TPproject/project/Public/Admin/Css/font-awesome.css">

    <script src="/TPproject/project/Public/Admin/Js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/Js/layer.js"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/static/h-ui.admin/js/H-ui.admin.js"></script>

    <script src="/TPproject/project/Public/Admin/Js/jquery.validation/jquery.validate.js" type="text/javascript"></script>


    <!-- Demo page code -->

    <style type="text/css">
        #line-chart {
            height:300px;
            width:800px;
            margin: 0px auto;
            margin-top: 1em;
        }
        .brand { font-family: georgia, serif; }
        .brand .first {
            color: #ccc;
            font-style: italic;
        }
        .brand .second {
            color: #fff;
            font-weight: bold;
        }
        .table>thead>tr>th
        {
          text-align: center;
        }
        .table>tbody>tr>td
        {
          text-align: center;
        }
    </style>



 
    <link rel="shortcut icon" href="/TPproject/project/Public/Admin/Img/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-57-precomposed.png">
  </head>
        
 <style type="text/css">
  .inv th{
    min-width: 60px;
    text-align: center;
  }
  .inv td{
    min-width: 60px;
    text-align: center;
  }
</style>       

<div class="container-fluid">
    <div class="row-fluid">
                    
    <div class="btn-toolbar">
        
        <!-- <a href="#myModal" data-toggle="modal" class="btn">删除</a> -->
      <div class="btn-group">
      </div>
    </div>
  <div class="well">
    
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="home">
    <form id="tab" method="post">
      <table class="inv">
      <tr>
        <thead>
          <th>产品名称</th>
          <th>颜色</th>
          <th>尺寸</th>
          <th>价格</th>
          <th>库存</th>
          
          <!-- <input type="text" value="" class="input-xlarge" id="pro_name" name='pro_name'> -->
        </thead>
      </tr>
    <?php if(is_array($inventory)): $i = 0; $__LIST__ = $inventory;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$inv): $mod = ($i % 2 );++$i;?><tr>
        <tbody>
          <td><?php echo ($product["pro_name"]); ?></td>
          <td>
            <select name="color" class="color" style="width:65px">
              <?php if(is_array($color)): $i = 0; $__LIST__ = $color;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$co): $mod = ($i % 2 );++$i;?><option value="<?php echo ($co["color_id"]); ?>" <?php if($co["color_id"] == $inv['color_id']): ?>selected<?php endif; ?>><?php echo ($co["color_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
            </select>
          </td>
          <td>
            <select name="size" style="max-width: 150px">
              <?php if(is_array($size)): $i = 0; $__LIST__ = $size;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$si): $mod = ($i % 2 );++$i;?><option value="<?php echo ($si["size_id"]); ?>" <?php if($si["size_id"] == $inv['size_id']): ?>selected<?php endif; ?>><?php echo ($si["size_scope"]); ?>(<?php echo ($si["re_age"]); ?>)</option><?php endforeach; endif; else: echo "" ;endif; ?>
            </select>
          </td>
          <td><input type="text" value="<?php echo ($inv["price"]); ?>" name='price' style="width: 100px"></td>
          <td><input type="text" value="<?php echo ($inv["inventory"]); ?>" class="input-xlarge" name='inventory' style="width: 100px"></td>
          <input type="hidden" value="<?php echo ($inv["pr_co_id"]); ?>" name='pr_co_id'>
          <input type="hidden" value="<?php echo ($inv["pro_id"]); ?>" name='pro_id'>
          <td><div class="btn btn-primary edit" onclick="inv_edit(this,'append')" style="position: relative;top: -4px"><i></i> 修改</div></td><!-- class="icon-save" -->
          <td><a href="javascript:;" onclick="inv_del(this,'append')" style="position: relative;top: -4px" data-toggle="modal" class="btn" >删除</a></td>
         <!--  <td>
            <a href="javascript:;" style="position: relative;top: -3px" onclick="del_attr('del?attr_id=<?php echo ($vo["attr_id"]); ?>')" role="button" data-toggle="modal"><i class="icon-remove"></i></a>
          </td>  -->
        </tbody>
        
      </tr><?php endforeach; endif; else: echo "" ;endif; ?>

      <tr>
        <tbody>
          <td><?php echo ($product["pro_name"]); ?></td>
          <td>
            <select name="color" id="color" style="width:65px">
              <?php if(is_array($color)): $i = 0; $__LIST__ = $color;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$co): $mod = ($i % 2 );++$i;?><option value="<?php echo ($co["color_id"]); ?>"><?php echo ($co["color_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
            </select>
          </td>
          <td>
            <select name="size" id="size" style="max-width: 150px">
              <?php if(is_array($size)): $i = 0; $__LIST__ = $size;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($vo["size_id"]); ?>"><?php echo ($vo["size_scope"]); ?>(<?php echo ($vo["re_age"]); ?>)</option><?php endforeach; endif; else: echo "" ;endif; ?>
            </select>
          </td>
          <td><input type="text" value=""  id="price" name='price' style="width: 100px"></td>
          <td><input type="text" value="" class="input-xlarge" id="inventory" name='inventory' style="width: 100px"></td>
          <input type="hidden" value="<?php echo ($pro_id); ?>" id="pro_id" name='pro_id'>
          <td><div class="btn btn-primary" id="add" onclick='inv_append("append")' style="position: relative;top: -4px"><i></i> 添加</div></td>
           <!-- class="icon-save" -->
        </tbody>
      </tr>
    </table>

    </form>

      </div>
      
  </div>

</div>




<script type="text/javascript">

  



function inv_append(url){
  
  var size = $("#size").val();
  var price = $("#price").val();
  var inventory = $("#inventory").val();
  var pro_id = $("#pro_id").val();
  var color = $("#color").val();

  if(price==''){
    layer.msg('价格未填写',{icon:2,time:1000});
    return false;
  }else if(inventory == ''){
    layer.msg('库存未填写',{icon:2,time:1000});
    return false;
  }else if(inventory <= 0){
    layer.msg('库存最少为1',{icon:2,time:1000});
    return false;
  }

  
  $.ajax({
    type:'post',
    url:url,
    data:{color_id:color ,size_id:size,price:price,inventory:inventory,pro_id:pro_id,status:1},
    dataType:'json',
    success:function(msg){
      if(msg.code==0){
        layer.msg(msg.info,{icon:2,time:1000});return false;
      }else{
        layer.msg(msg.info,{icon:1,time:1000},function(index){
          window.location.replace("append?pro_id="+pro_id);
        });
      }
      
    }
  })
}

// $('.edit').click(function(){
//   var color = $(this).html();
//   alert(color);return false;
// })


function inv_edit(obj,url){
  var color = $(obj).parent().siblings().children().eq(0).val();
  // var color = $(obj).parent().prev().prev().prev().prev().children().val();
  var size = $(obj).parent().siblings().children().eq(1).val();
  var price = $(obj).parent().siblings().children().eq(2).val();
  var inventory = $(obj).parent().siblings().children().eq(3).val();
  var pr_co_id = $(obj).parent().siblings().eq(5).val();
  var pro_id = $(obj).parent().siblings().eq(6).val();
  
  

  if(price==''){
    layer.msg('价格未填写',{icon:2,time:1000});
    return false;
  }else if(inventory == ''){
    layer.msg('库存未填写',{icon:2,time:1000});
    return false;
  }else if(inventory <= 0){
    layer.msg('库存最少为1',{icon:2,time:1000});
    return false;
  }

  
  $.ajax({
    type:'post',
    url:url,
    data:{color_id:color ,size_id:size,price:price,inventory:inventory,pr_co_id:pr_co_id,status:2,pro_id:pro_id},
    dataType:'json',
    success:function(msg){
      if(msg.code==0){
        layer.msg(msg.info,{icon:2,time:1000});return false;
      }else{
        layer.msg(msg.info,{icon:1,time:1000},function(index){
          
        });
      }
      
    }
  })
}


function inv_del(obj,url){
  var pr_co_id = $(obj).parent().siblings().eq(5).val();
  var pro_id = $(obj).parent().siblings().eq(6).val();
  
  layer.confirm('确定删除吗',function(index){
    $.ajax({
      type:'post',
      url:url,
      data:{pr_co_id:pr_co_id,status:3},
      dataType:'json',
      success:function(msg){
        if(msg.code==0){
          layer.msg(msg.info,{icon:2,time:1000});return false;
        }else{
          layer.msg(msg.info,{icon:1,time:1000},function(index){
            window.location.replace("append?pro_id="+pro_id);
          });
        }
        
      }
    })
  });
  
}
  
  
</script>